/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.pressa.client.service.FMIPackets;

/**
 *
 * @author Lborri
 */
public class FMI2600 {

    String packet;

    public FMI2600(String parameter) {
        packet = parameter;
    }

    public String getTextMessage() {
        String message = null;
        message = packet.substring(packet.indexOf(",")+81, packet.indexOf(";")-2);
        message = convertHexToString(message);
        return message;
    }
    
    public String getTime(){
        String time = null;
        time = packet.substring(packet.indexOf(",")+ 9, packet.indexOf(",") + 17);
        
        //Cambiar a Date!!!
        
        
        return time;
    }

    public String convertHexToString(String hex) {

        StringBuilder sb = new StringBuilder();
        StringBuilder temp = new StringBuilder();
        for (int i = 0; i < hex.length() - 1; i += 2) {
            String output = hex.substring(i, (i + 2)); //grab the hex in pairs
            int decimal = Integer.parseInt(output, 16); //convert hex to decimal
            sb.append((char) decimal); //convert the decimal to character
            temp.append(decimal);
        }
        return sb.toString();
    }
}
